﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void ButtonIniciarSesion_Click(object sender, EventArgs e)
    {
        string msg_error = "";
        try
        {
            DataSetEsquemaAppCeii.USUARIODataTable ds = new DataSetEsquemaAppCeii.USUARIODataTable();
            UsuarioBLL usrbll = new UsuarioBLL();
            ds = usrbll.verPass(int.Parse(TextBoxRut.Text));
            string pass = ds.Rows[0][6].ToString();
            string tipo = ds.Rows[0][7].ToString();
            string estd = ds.Rows[0][8].ToString();
            if (string.Compare(pass.Trim(), TextBoxPass.Text.Trim()) == 0)
            {
                if(string.Compare(estd.ToLower().Trim(), "true")==0){
                    //autenticado
                    if(string.Compare(tipo.ToLower().Trim(), "admin")==0){
                        VariablesGlobales.GetInstance().setUsuario(TextBoxRut.Text.ToLower().Trim());
                        Response.Redirect("Modulos/Administrador/VistaControl/AdminUsuarios.aspx");
                    }
                    else{
                        VariablesGlobales.GetInstance().setUsuario(TextBoxRut.Text.ToLower().Trim());
                        Response.Redirect("index.aspx");
                    }
                }
                else{
                    msg_error = "su cuenta se encuentra inactiva.";
                }
            }
            else{
                //no autenticado
                msg_error = "usuario o clave incorrectos.";
            }
        }
        catch
        {
            msg_error = "usuario o clave incorrectos.";
        }
        LabelMsg.Text = msg_error;
    }
}
